<?php
namespace app\controller;

use app\BaseController;
use app\model\CertificateModel;
use app\model\ClassifyModel;
use think\facade\View;

/**
 * 教育培训
 */
class Train extends BaseController
{

    /**
     * 教育培训
     */
    public function index($cid = 14)
    {
        $catid = $cid;
        View::assign('cid', $catid);


        $classify = ClassifyModel::where(['deleted' => 0, 'id'=>$catid])->find();
        View::assign('classify', $classify);

        $this->getArticleList($catid);

        return View::fetch();
    }


    /**
     * 证书查询
     */
    public function cert($cid = 100)
    {
        $catid = $cid;
        View::assign('cid', $catid);

        return View::fetch();
    }

    /**
     * 提交查询
     * certSubmit
     */
    public function certSubmit()
    {
        // post
        $data = $this->request->post();
        // 判断name和certificateNumber 是否为空
        if (empty($data['name']) || empty($data['certificateNumber'])) {
            return json(['code' => 0, 'msg' => '姓名和证书编号不能为空']);
        }

        // 查询
        $where = [
            'name' => $data['name'],
            'certificate_number' => $data['certificateNumber'],
            'deleted' => 0
        ];
        $data = CertificateModel::where($where)->find();
        if ($data) {
            // 查询到数据
            return json(['code' => 1, 'msg' => '查询成功', 'data' => $data]);
        } else {
            // 没有查询到数据
            return json(['code' => 0, 'msg' => '没有查询到数据']);
        }
    }


}
